<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Q Light Controller Plus - Script Editor</TITLE>
<SCRIPT SRC="utility.js" TYPE="text/javascript"></SCRIPT>
<link href="style.css" rel="stylesheet" type="text/css" />
</HEAD>
<BODY onLoad="replaceqrc()">

<H1>Script Editor</H1>
<P>
The Script Editor, as its name suggests, is used to edit
<IMG SRC="qrc:/script.png" align="absmiddle"> <A HREF="concept.html#Script">Script</A> functions.<br>
It basically consists in a text editor where the user can write a script using a meta-language with
a syntax described below.<br>
The script can be manually modified if you have a full understanding of the language syntax, otherwise
a few helper buttons are available on the rightmost side of the editor to speed up and facilitate the
script creation/editing.<br>
Each line of a script will be executed by QLC+ in a sequential order.
</P>

<H3>Controls</H3>

<TABLE BORDER=1 class="qlcTable">
 <TR>
  <TD>
   <img src="qrc:/player_play.png" />
  </TD>
  <TD>
   Enable the output and run the Script to test its execution
  </TD>
 </TR>
 <TR>
  <TD>
   <B>Script name</B>
  </TD>
  <TD>
   Change the name of the Script.
  </TD>
 </TR>
 <TR>
  <TD>
   <IMG SRC="qrc:/edit_add.png">
  </TD>
  <TD>
   When clicked, this button will display a popup where you can choose the script
   snippet you want to insert at the current cursor position in the editor.
   <UL>
    <LI><IMG SRC="qrc:/function.png" width=24 align="absmiddle"> <B>Start Function</B>: Opens the
      <A HREF="selectfunction.html">Functon Selection</A> dialog to select a Function to be started.<br>
      This operation will automatically add a comment at the end of the line of code, with the
      QLC+ name of the selected Function.
    </LI>
    <LI><IMG SRC="qrc:/fileclose.png" width=24 align="absmiddle"> <B>Stop Function</B>: Opens the
      <A HREF="selectfunction.html">Functon Selection</A> dialog to select a Function to be stopped.
      If at the moment of execution of this line of code the selected Function is not running,
      this instruction will have no effect.<br>
      This operation will automatically add a comment at the end of the line of code, with the
      QLC+ name of the selected Function.
    </LI>
    <LI><IMG SRC="qrc:/blackout.png" width=24 align="absmiddle"> <B>Blackout</B>: Opens dialog
      requesting whether blackout should be turned on or off.
    </LI>
    <LI><IMG SRC="qrc:/fixture.png" width=24 align="absmiddle"> <B>Set Fixture</B>: Opens
      the Fixture Channels selection dialog, where you can choose the channels you want to control
      with the Script. If multiple channels are selected, this operation will add one line of code
      for each selected channel. By default, the DMX value generated by this opration will be 0 and has
      to be changed manually with the script text editor.<br>
      This operation will automatically add a comment at the end of the line of code, with the
      QLC+ name of the selected fixtures and channels.
    </LI>
    <LI><IMG SRC="qrc:/player_play.png" width=24 align="absmiddle"> <B>System Command</B>: Opens a file dialog
      to choose the external program/script to run. Please note that the selected file must be executable to
      be accepted. Once a file has been selected another dialog will ask to enter the program/script
      arguments. If none are required, just leave the field empty.
    </LI>
    <LI><IMG SRC="qrc:/speed.png" width=24 align="absmiddle"> <B>Wait</B>: Opens a dialog requesting
      the time to be waited before the script can execute the next instruction
    </LI>
    <LI><IMG SRC="qrc:/label.png" width=24 align="absmiddle"> <B>Comment</B>: Opens a dialog requesting
      the text of the comment to insert at the cursor position in the editor.<br>
      A comment has a C language style appearance: it starts with "//" and everything until the end
      of the line is then considered a comment
    </LI>
    <LI><IMG SRC="qrc:/other.png" width=24 align="absmiddle"> <B>Random Number</B>: Opens a dialog
      requesting the range of values where to perform a randomization of a number. The resulting code snippet
      will be inserted at the editor current cursor position.<br>
      This can be useful to randomize DMX values set through the setfixture keyword. See below.
    </LI>
    <LI><IMG SRC="qrc:/fileopen.png" width=24 align="absmiddle"> <B>File Path</B>: Open a file dialog
      to select a file. The absolute path and the file name will be insterted at the editor current position.<br>
      If a path contains spaces, it will be written within quotes
    </LI>
   </UL>
  </TD>
 </TR>
 <TR>
  <TD>
   <IMG SRC="qrc:/editcut.png">
  </TD>
  <TD>
   Cut the currently selected text in the editor for a later paste
  </TD>
 </TR>
 <TR>
  <TD>
   <IMG SRC="qrc:/editcopy.png">
  </TD>
  <TD>
   Copy the currently selected text in the editor for a later paste
  </TD>
 </TR>
 <TR>
  <TD>
   <IMG SRC="qrc:/editpaste.png">
  </TD>
  <TD>
   Paste a previously cut or copied text at cursor position in the editor
  </TD>
 </TR>
 <TR>
  <TD>
   <IMG SRC="qrc:/undo.png">
  </TD>
  <TD>
   Undo the last performed operation on the editor
  </TD>
 </TR>
 <TR>
  <TD>
   <IMG SRC="qrc:/check.png">
  </TD>
  <TD>
   Check the Script syntax. A popup message will be displayed indicating if the Script is
   OK or the line numbers where syntax errors have been found.
  </TD>
 </TR>
</TABLE>

<H3>Language syntax</H3>
<P>
The QLC+ Script meta-language is based on a <B>keyword:value</B> model, with some insertions of
C language syntax rules.<br>
Each line of code is parsed by the QLC+ engine and verified to detect the presence of
syntax errors.<br>
Here's a table describing each keyword accepted by the Script engine and its syntax.
</P>

<TABLE BORDER=1 class="qlcTable">
 <TR>
  <TD>startfunction</TD>
  <TD>
    <B>Type</B>: keyword<br>
    <B>Description</B>: starts a QLC+ Function with the given ID.<br>
    <B>Syntax</B>: startfunction:functionID<br><br>
    <I>functionID</I> is an integer number of the ID assigned by QLC+ to a Function. Since IDs are not exposed to
    QLC+ users, in this case it is convenient to use the helper button on the rightmost side of the editor,
    which also add a comment with the Function name.<br>
    Eventually a user will learn the ID of a Function and therefore use it to manually add more code
    to the script.<br>
    <B>Example</B>: <PRE>startfunction:2 // Green scene</PRE>
  </TD>
 </TR>
 <TR>
  <TD>stopfunction</TD>
  <TD>
    <B>Type</B>: keyword<br>
    <B>Description</B>: stops a running QLC+ Function with the given ID.<br>
    <B>Syntax</B>: stopfunction:functionID<br><br>
    <I>functionID</I> is an integer number of the ID assigned by QLC+ to a Function. See <I>startfunction</I>
    description.<br>
    <B>Example</B>: <PRE>stopfunction:0 // Blue scene</PRE>
  </TD>
 </TR>
 <TR>
  <TD>blackout</TD>
  <TD>
    <B>Type</B>: keyword<br>
    <B>Description</B>: turns blackout on or off.<br>
    <B>Syntax</B>: blackout:on|off<br><br>
    <I>functionID</I> is an integer number of the ID assigned by QLC+ to a Function. See <I>startfunction</I>
    description.<br>
    <B>Examples</B>:
      <PRE>blackout:on
blackout:off</PRE>
  </TD>
 </TR>
 <TR>
  <TD>systemcommand</TD>
  <TD>
    <B>Type</B>: keyword<br>
    <B>Description</B>: execute a program or a script at the provided absolute path with the (optional) provided arguments.<br>
    <B>Syntax</B>: systemcommand:programPath arg:arg1 arg:arg2 ... arg:argN<br><br>
    <I>programPath</I> is the absolute path of an executable program or script. For example "/usr/bin/vlc" or "C:\Tools\myTool.exe"<br>
    If the path to an executable contains spaces, it must be written between quotes.<br>
    <I>arg1 ... argN</I> are the arguments to be used when executing <I>programPath</I>. If no arguments are
    needed, then the arg: keywords are not necessary.<br>
    If an argument contans spaces it must be written between quotes.<br>
    <B>Examples</B>:
      <PRE>systemcommand:/usr/bin/vlc arg:-f arg:/home/user/video.mp4 // plays my video with VLC in fullscreen
systemcommand:"C:\Program Files\Tools\My Tool.exe" arg:"D:\My Files\My file.txt"</PRE>
  </TD>
 </TR>
 <TR>
  <TD>setfixture</TD>
  <TD>
    <B>Type</B>: keyword<br>
    <B>Description</B>: sets a QLC+ Fixture channel to the provided DMX value.<br>
    <B>Syntax</B>: setfixture:fixtureID ch:channelIndex val:DMXValue<br><br>
    <I>fixtureID</I> is an integer number of the ID assigned by QLC+ to a Function. Since IDs are not exposed to
    QLC+ users, in this case it is convenient to use the helper button on the rightmost side of the editor,
    which also add a comment with the fixture and channel name.<br>
    Eventually a user will learn the ID of a fixture and the index of a channel and therefore use them
    to manually add more code to the script.<br>
    <I>channelIndex</I> is an integer number representing the fixture channel number. Channels indices here start from 0.<br>
    <I>DMXValue</I> is the actual DMX value to be set to the specified fixture channel. It ranges from 0 to 255<br>
    <B>Example</B>: <PRE>setfixture:0 ch:1 val:135 // Generic RGB, Red. Sets the red channel of a Generic RGB fixture to DMX value 135</PRE>
  </TD>
 </TR>
 <TR>
  <TD>wait</TD>
  <TD>
    <B>Type</B>: keyword<br>
    <B>Description</B>: wait for the provided amount of time before executing the next line of code.<br>
      Note that a wait time can be randomized too, following the <i>random</i> syntax described below.<br>
    <B>Syntax</B>: wait:time<br><br>
    <I>time</I> can be either an integer number of milliseconds or a string
    representing the wait time in the QLC+ way: **h**m**s.**<br>
    <B>Examples</B>:
      <PRE>wait:1800 // Waits for 1 second and 800 milliseconds
wait:03s.20 // Waits for 3 seconds and 200 milliseconds</PRE>
  </TD>
 </TR>
 <TR>
  <TD>comments</TD>
  <TD>
    <B>Type</B>: Helper macro<br>
    <B>Description</B>: comments can be inserted at any position in the script code and they do not affect the
    script execution. They are normally used to give a meaning to a line of code.<br>
    QLC+ Scripts comment follow the C Language style rule of the "//" syntax. Basically
    everything written after "//" will be considered a comment until the end of the line of code.<br>
    So pay a particular attention to not writing meaningful code after a "//" and expect it to be
    run, cause it won't.<br>
    Comments can be added at the end of a Script line of code or they can take a whole line, for example to describe
    an entire block of code.
  </TD>
 </TR>
 <TR>
  <TD>random</TD>
  <TD>
    <B>Type</B>: Helper macro<br>
    <B>Description</B>: generates a random integer number between the provided minimum and maximum values<br>
    <B>Syntax</B>: random(min,max)<br><br>
    <I>min</I> is the minimum value the randomization can reach. It can be either an integer number or a time string<br>
    <I>max</I> is the maximum value the randomization can reach. It can be either an integer number or a time string<br>
    <B>Examples</B>:
    <PRE>wait:random(02s.00,05s.00) // Waits a random time between 2 and 5 seconds

// set channel 3 of fixture with ID:1 to a random DMX value between 20 and 235
setfixture:1 ch:2 val:random(20,235)</PRE>
  </TD>
 </TR>
</TABLE>

</BODY>
</HTML>
